﻿namespace SBlogCore.Common.CacheExtend
{
    public interface ISBlogCoreCache
    {
        /// <summary>
        /// 获取数据
        /// </summary>
        /// <typeparam name="TResult"></typeparam>
        /// <param name="key"></param>
        /// <returns></returns>

        TResult? Get<TResult>(string key);
        /// <summary>
        /// 存储数据
        /// </summary>
        /// <param name="key"></param>  
        /// <param name="value"></param>
        /// <returns></returns>
        void Create<TResult>(string key, TResult value);
        /// <summary>
        /// 存储数据
        /// </summary>
        /// <param name="key"></param>
        /// <param name="value"></param>
        /// <param name="timeout"></param>
        /// <returns></returns>
        void Create<TResult>(string key, TResult value, long timeout);
        /// <summary>
        /// 获取或创建
        /// </summary>
        /// <typeparam name="TResult"></typeparam>
        /// <param name="key"></param>
        /// <param name="valueFactory"></param>
        /// <returns></returns>
        TResult? GetOrCreate<TResult>(string key, Func<TResult>? valueFactory);

        /// <summary>
        /// 获取或创建
        /// </summary>
        /// <typeparam name="TResult"></typeparam>
        /// <param name="key"></param>
        /// <param name="valueFactory"></param>
        /// <param name="timeout"></param>
        /// <returns></returns>
        TResult? GetOrCreate<TResult>(string key, Func<TResult>? valueFactory, long timeout);
        /// <summary>
        /// 异步获取
        /// </summary>
        /// <typeparam name="TResult"></typeparam>
        /// <param name="key"></param>
        /// <returns></returns>
        Task<TResult?> GetAsync<TResult>(string key);
        /// <summary>
        /// 异步存储数据
        /// </summary>
        /// <param name="key"></param>
        /// <param name="value"></param>
        /// <returns></returns>
        Task CreateAsync<TResult>(string key, TResult value);
        /// <summary>
        /// 异步存储数据
        /// </summary>
        /// <param name="key"></param>
        /// <param name="value"></param>
        /// <param name="timeout"></param>
        /// <returns></returns>
        Task CreateAsync<TResult>(string key, TResult value, long timeout);
        /// <summary>
        /// 获取或者创建缓存
        /// </summary>
        /// <typeparam name="TResult"></typeparam>
        /// <param name="key"></param>
        /// <param name="valueFactory"></param>
        /// <returns></returns>
        Task<TResult?> GetOrCreateAsync<TResult>(string key, Func<Task<TResult>>? valueFactory);

        /// <summary>
        /// 异步获取或者创建缓存
        /// </summary>
        /// <typeparam name="TResult"></typeparam>
        /// <param name="key"></param>
        /// <param name="valueFactory"></param>
        /// <param name="timeout"></param>
        /// <returns></returns>
        Task<TResult?> GetOrCreateAsync<TResult>(string key, Func<Task<TResult>>? valueFactory, long timeout);
        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="cacheKey"></param>
        void Remove(params string[] cacheKey);
        /// <summary>
        /// 异步删除
        /// </summary>
        /// <param name="cacheKey"></param>
        /// <returns></returns>
        Task RemoveAsync(params string[] cacheKey);
        /// <summary>
        /// 根据分区删除
        /// </summary>
        /// <param name="pattern"></param>
        /// <returns></returns>
        Task<long> RemoveByPatternAsync(string pattern);
    }
}
    